import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/business_customer/page/business_customer_details_service_xyk_details.dart';

class BusinessCustomerDetailsServiceXykTab extends StatefulWidget {

  BusinessCustomerDetailsServiceXykTab({Key key, @required this.vipId, @required this.cardTypeId, @required this.inputApi}) : super(key: key);

  final String vipId;

  final String cardTypeId;

  final String inputApi;

  @override
  _BusinessCustomerDetailsServiceXykTabState createState() => _BusinessCustomerDetailsServiceXykTabState();

}

class _BusinessCustomerDetailsServiceXykTabState extends State<BusinessCustomerDetailsServiceXykTab> with AutomaticKeepAliveClientMixin {

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Column(
      children: [
        Container(
          padding: const EdgeInsets.all(12.0),
          margin: const EdgeInsets.all(12.0),
          color: Colors.white,
          child: BaseRefreshGirdViewComponent(
            path: widget.inputApi,
            params: {'vipId': widget.vipId, 'cardTypeId': widget.cardTypeId},
            buildItem: _buildListItem,
            controller: new BaseRefreshController(),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, crossAxisSpacing: 5, mainAxisSpacing: 12),
          ),
        ),
      ],
    );
  }

  Widget _buildListItem(Map<String, dynamic> item, int index) {
    String facadeImage = BaseUtils.getKeyData(item, 'facadeImage').toString();
    String wishCardTypeName = BaseUtils.getKeyData(item, 'wishCardTypeName').toString();
    double imageWidth = 80.0;
    return InkWell(
      onTap: () => _goDepotVipDetailsXykDetails(item),
      child: Container(
        alignment: Alignment.center,
        child: Stack(
          children: [
            BaseImageComponent(imageUrl: facadeImage, width: imageWidth),
            Positioned(
            bottom: 0,
            width: imageWidth,
            child: Container(alignment: Alignment.center, height: 24.0, child: Text(wishCardTypeName, style: Theme.of(context).textTheme.bodyText2.copyWith(color: Colors.white)), color: Color(0xFF333333).withAlpha(102),)),
          ],
        ),
      ),
    );
  }

  void _goDepotVipDetailsXykDetails( dynamic item ) {
    String cardId = BaseUtils.getKeyData(item, 'cardId').toString();
    BaseRouterUtil.getInstance().pushNamed(BusinessCustomerDetailsServiceXykDetails.sName, arguments: { 'cardId': cardId });
  }

  @override
  bool get wantKeepAlive => true;

}
